home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4518 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  125 lines

  1. Path: solon.com!not-for-mail
  2. From: seebs@solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,comp.programming.contests
  4. Subject: NEW CONTEST!
  5. Followup-To: comp.lang.c.moderated
  6. Date: 5 Feb 1996 08:45:02 -0600
  7. Organization: Usenet Fact Police (Undercover)
  8. Sender: clc@solutions.solon.com
  9. Approved: clc@solutions.solon.com
  10. Message-ID: <4f555e$6tr@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. *please notice and respect followups*
  14.  
  15. Now, since I'm about to get the prize from the last contest to a post office
  16. for shipping, it's time for a ....
  17.  
  18.         NEW PROGRAMMING CONTEST!
  19.  
  20. This is the 2nd comp.lang.c.moderated contest.  Prize is TBD.
  21.  
  22. The subject:  Homework.
  23.  
  24. The contest goals:  We provide three typical questions - a stereotypical
  25. first year C programming take home test.  Your goal: Provide the most
  26. misleading accurate answers possible.
  27.  
  28. Requirements:
  29. 1.  You must be able to convince the judge (me) that you have fulfilled the
  30. requirements of each problem.
  31. 2.  Your code must run on the majority of likely platfroms, and contain no
  32. undefined behavior (that I or anyone else reading can detect.)
  33. 3.  Your code must be utterly unacceptable as an answer, at least, from
  34. a first year student.  :)
  35.  
  36. Bonus points for partially true and completely misleading comments, bad style,
  37. or clever algorithms.
  38.  
  39. I am using this contest idea because I had a lot of fun writing the posts
  40. I use as examples.
  41.  
  42. Examples:
  43.  
  44. 1.  Compliant but missing the point.
  45.  
  46. >In article <4e4cu4$95f@vixen.cso.uiuc.edu>, HOTARD  <jhotard> wrote:
  47. >>I am writing a program that looks at a character and then determines if it is a
  48. >>letter or number.  This program must use the switch command ...
  49.  
  50. >main() {
  51. >    int c, x, printf();
  52. >    c = getchar();
  53. >    switch (x = ((c = (unsigned char) c), /* try to ensure a legal char. */
  54. >        ((!!isdigit(c)) << 1) | ((!!isalpha(c)) << 0)))
  55. >    default:
  56. >        printf(
  57. >    (x == 0 ? "'\\x%x' is neither a letter nor a number.\n" :
  58. >     (x == 1 ? "'%c' is a letter.\n" : (x == 2 ? "'%c' is a number.\n" :
  59. >      (x == 3 ? "'%c' is both a letter and a number.\n" :
  60. >        "'\\x%x' is odd.\n"))), c);
  61. >    return 0;
  62. >}
  63.  
  64. 2.  Misleading.
  65. >>For each tyep listed below, explain what sort of object can be stored in 
  66. >>variables of that type and igve 2 examples:
  67.  
  68. >>a.  char
  69.  
  70. >    A char holds an integer value.  Examples:
  71.  
  72. >    char coal = 32;
  73. >    char woman = 16;
  74.  
  75. >>b.  int
  76.  
  77. >    An int holds a numeric value.  Examples:
  78.  
  79. >    int pi = 3.14159;
  80. >    int i = sqrt(-1);
  81.  
  82. >>c.  float
  83.  
  84. >    A float variable can change during execution.  Examples:
  85.  
  86. >    float f = 1, g = 3;
  87. >    f = g; /* assigns g to f, causing f to 'float' */
  88.  
  89. >>d.  long int
  90.  
  91. >    A long int has more digits than an int.  Examples:
  92.  
  93. >    long int ten = 00000012;
  94. >    long int hex = 0x15;
  95.  
  96. >    You can enter a long using "0x" to mean hex.
  97.  
  98. ---end examples
  99.  
  100. Feel free to be twisted, confusing, or malicious.  All answers must be in C.
  101. Answers must be conforming, and should be strictly conforming if at all
  102. possible.
  103.  
  104. The questions:
  105. (Answer at least one; I will probably give a prize for the best answer to
  106. each question.)
  107.  
  108. 1.  Write a program which asks for the user's name, age, and any other
  109. information you want, and which prints a chatty greeting message, and
  110. writes the user's information to a file.
  111.  
  112. 2.  Write a function which compares two strings, ignoring case.  You should
  113. use the islower() and toupper() commands.  Write a small program which uses
  114. this function to compare its arguments.
  115.  
  116. 3.  Write a program which plays tic-tac-toe against itself.  It should
  117. be good enough to draw consistently.
  118.  
  119. -s
  120. -- 
  121. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  122. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  123. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  124. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  125.